package deibay.util;

import java.io.Serializable;


/**
 * Tuple to associate two objetcts.
 */
public class Pair<A extends Serializable, B extends Serializable>  implements Serializable {

       public Pair(A first, B second) {
               this.first = first;
               this.second = second;
       }

       public A getFirst() { return this.first; }
       public B getSecond() { return this.second; }

       @Override
       public String toString() {
               return "(" + this.first + ", " + this.second + ")";
       }

       private static boolean equals(Object x, Object y) {
               return (x == null && y == null) || (x != null && x.equals(y));
       }

       @Override
       public boolean equals(Object other) {
               return other instanceof Pair &&
                       equals(this.first, ((Pair) other).first) &&
                       equals(this.second, ((Pair) other).second);
       }

       @Override
       public int hashCode() {
               if (this.first == null)
                       return (this.second == null) ? 0 : this.second.hashCode() + 1;
               else if (this.second == null)
                       return this.first.hashCode() + 2;
               else
                       return this.first.hashCode() * 17 + this.second.hashCode();
       }

       private final A first;
       private final B second;

       private static final long serialVersionUID = 1L;
}

